package cn.hloger.spider.factory;

import org.springframework.http.client.SimpleClientHttpRequestFactory;

import java.io.IOException;
import java.net.HttpURLConnection;

/**
 * RestTemplate获取重定向后的连接
 * 因为RestTemplate自动重定向,使用这个工厂类拒绝重定向,从而拿到状态码302的值
 *
 * @author huanglong
 * @Description TODO
 * @data 2022/9/13
 */
public class NoRedirectSimpleClientHttpRequestFactory extends SimpleClientHttpRequestFactory {

    @Override
    protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
        super.prepareConnection(connection, httpMethod);
        connection.setInstanceFollowRedirects(false);
    }
}